import { ADD_CONFIG, UPDATA_CONFIG } from '../actionTypes'
import Ajax from 'lib/Ajax'
import { message } from 'antd'

/* 
 * redux-thunk
export function addConfig(dictionaryCode){
  return dispatch => {
    setTimeout(()=>{
      dispatch(updataConfig(dictionaryCode, "test"+Math.random()))
    },5000);
  }
}
*/

export function addConfig(key, dictionaryCode){
  return dispatch => {
    Ajax({
      url: '/dic/dicList',
      data: {
        "dicTypeId": dictionaryCode
      },
      success: function(data){
        dispatch(updataConfig(key, data));
      },
      error: function(error){
        message.error(error);
      }
    });
  }
}

export function updataConfig(key, value) {
  return {
    type: UPDATA_CONFIG,
    key,
    value
  }
}